home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
JOHNLOVE
/
C_SOURCE
/
CMYTEAR.C
< prev
next >
Wrap
Text File
|
1992-02-29
|
8KB
|
232 lines
/*********************************************************
"CmyTear.c"
by John A. Love, III [Washington Apple Pi Users' Group]
using Symantec's "THINK C", v 5.0.1
... as derived from their "TCL Starter" files
*********************************************************/
#include "CmyTear.h"
extern CBureaucrat *gGopher;
extern short gClicks;
extern CDesktop *gDesktop;
void CCustomSelector::DrawItem (short theItem, Rect *theBox) {
/* Passed area rect is in QuickDraw coordinates */
#define kMAC 3000
Boolean savedAlloc;
PicHandle myPic;
Rect pictRect;
switch (theItem) {
case 1:
savedAlloc = SetAllocation(kAllocCanFail);
myPic = GetPicture(kMAC);
pictRect = (**myPic).picFrame;
SetAllocation(savedAlloc);
FailNILRes(myPic);
CenterRects(&pictRect, theBox);
DrawPicture(myPic, &pictRect);
ReleaseResource(myPic); /* Do NOT need after drawing. */
break;
default:
inherited::DrawItem(theItem, theBox); // Empty for now.
break;
} /* only 1 item */
} /* DrawItem */
void CCustomSelector::DoClick (Point hitPt, short modifierKeys, long when) {
short itemHit, count;
long finalTicks;
itemHit = FindItem(hitPt);
// Ignore all clicks beyond 2:
if ( (itemHit != selection) && (gClicks == 2) ) {
for (count = 2; count > 0; count--) {
HiliteItem(itemHit, hiliteON);
Delay(20, &finalTicks);
HiliteItem(itemHit, hiliteOFF);
Delay(20, &finalTicks);
}
gDesktop->Prepare(); // ??????????
itsSupervisor->DoCommand(-(( (long)commandBase <<16 ) + itemHit));
}
} /* DoClick */
void CTearMenuDir::ITearMenuDir (CApplication *aSupervisor) {
#define kTearMenu 1000
#define kMAC 3000
CCustomSelector *myMenu;
CSelectorMDEF *myMDEF;
Boolean savedAlloc;
PicHandle myPic;
Rect pictRect;
/* Retrieve window with ID = kTearMenu and set = itsWindow from
** CTearOffMenu's superclass = CDirector. Pass "this" as the
** window's Supervisor. "this" = CmyApp's instance variable =
** itsTearMenu of Class = CTearOffMenu because the ORIGINAL
** object that sent us here to begin with was itsTearMenu.
**
** "A director is a bureaucrat that supervises a window". The
** above is consistent with this because CTearOffMenu descends
** from CDirector. Down a little bit we will make the supervisor
** of the CGridSelector (is a CSelector is a CPanorama is a CPane)
** our application. Normally, the supervisor of a Pane is a doc. */
inherited::ITearOffMenu(aSupervisor, kTearMenu);
savedAlloc = SetAllocation(kAllocCanFail);
myPic = GetPicture(kMAC);
SetAllocation(savedAlloc);
FailNILRes(myPic);
pictRect = (**myPic).picFrame;
OffsetRect(&pictRect, -pictRect.left, - pictRect.top); // Zero origin.
ReleaseResource(myPic); /* Do NOT need after getting frame. */
myMenu = new (CCustomSelector);
myMenu->IGridSelector(
itsWindow, /* From superclass of CTearOffMenu */
aSupervisor, /* My application */
0, 0,
sizELASTIC, sizELASTIC,
0, /* Initial item to select */
kTearMenu, /* Command Base */
1, 1, /* # of rows & columns */
pictRect.right + 2, /* box width & height */
pictRect.bottom + 2
);
myMenu->SetGridOn(false); // IGridSelector sets = true.
myMenu->FitToEnclosure(true, true);
myMenu->Activate();
itsPane = myMenu; /* myMDEF->DrawMenu calls itsPane->Draw */
/* Reset the minimum & maximum sizes of a window.
** TCL has these preset = 100 & GrayRgn's rgnBBox: */
SetRect(&itsWindow->sizeRect,
pictRect.left - 1,
pictRect.top - 1,
pictRect.right + 3,
pictRect.bottom + 3);
/* Change the size of all the window's sub-view(s)
** which is now just my CGridSelector = myMenu.
** Leave a blank 1 pixel border around PICTure
** so PICTure does NOT touch the window frame: */
itsWindow->ChangeSize(pictRect.right + 2, pictRect.bottom + 2);
/* Leave same blank space in setting margins. This
** margin ALSO includes the regular window frame.
** So we have a 1 pixel blank space, a 1 pixel frame
** AND a 10 pixel drag bar on top: */
SetRect(&margins, 2, 12, 2, 2);
myMDEF = new (CSelectorMDEF);
myMDEF->ISelectorMDEF(kTearMenu, myMenu, this);
itsWindow->MoveOffScreen(); // Keep handy, but out of the way. */
itsWindow->Select();
/* ISelectorMDEF initializes its superclass by calling IPaneMDEF which
** calls IMenuDefProc(kTearMenu) to fill-in the zero-bytes of attached
** 'MDEF' resource. This latter method sets:
** (**theMDEF).itsMenuDefProc = this;
** where "this" = the ORIGINAL object that was sent the IMenuDefProc
** message. The originator = myMDEF since myMDEF sent ISelectorMDEF
** which sent IMenuDefProc. So, for example, when the GenericMDEF
** calls:
** itsMenuDefProc->DrawMenu(...);
** myMDEF->DrawMenu really gets called which method CSelectorMDEF
** inherits from CPaneMDEF. Ditto for myMDEF->SizeMenu.
** myMDEF->ChooseItem is a method directly within CSelectorMDEF.
** This ChooseItem method determines whether you╒ve instigated a
** tear by testing if you dragged to the side or just downward as
** you╒d normally do to just choose an item.
**
** The DrawMenu routine of CPaneMDEF calls itsPane->Draw where
** "itsPane" is an instance variable of CPaneMDEF. Note above
** that I╒ve stuffed a CGridSelector object {which is a CSelector
** is a CPanorama which descends from CPane} into the "itsPane"
** belonging to CTearOffMenu. Same pane, but different objects
** or Classes. HOW ???
**
** Below we pass CTearOffMenu's "itsPane" to ISelectorMDEF which, after
** it calls IMenuDefProc, calls IPaneMDEF thereby initializing CSelectorMDEF's
** superclass. IPaneMDEF stores the passed CTearOffMenu's "itsPane" in
** CPaneMDEF╒s "itsPane". IPaneMDEF also stuffs the passed CTearOffMenu
** object (= "this" = last parm passed to ISelectorMDEF) into CPaneMDEF's
** "itsTearOffMenu".
**
** myMDEF->DrawMenu, then, effectively calls CPandMDEF::DrawMenu which
** calls itsPane->Draw where "itsPane" = myMenu of class CGridSelector.
** So ... CGridSelector::Draw gets called and it draws all the items in
** your grid by calling CGridSelector::DrawItem. TCL's "DrawItem" method
** is empty, so you MUST override it.
**
** CPaneMDEF::SizeMenu retrieves the width & height of CPaneMDEF::itsPane
** and stuffs them into the MENU fields = menuWidth & menuHeight.
**
** CSelectorMDEF::ChooseItem, as I have previously stated, tests for a
** tear-off by following your dragging motion. If you╒ve dragged beyond
** the confines of the pulled-down Menu and NOT stayed within them (as you
** would for a normal choose), and if CPaneMDEF::itsTearOffMenu is not NULL
** and if the Menu itself is enabled THEN we call the TearOffMenu
** method which CSelectorMDEF inherited from CPaneMDEF. This last method
** calls CPaneMDEF::itsTearOffMenu->TornOff which simply creates a
** new(CTearChore) and initializes it. We pass ╥this╙ to ITearChore,
** meaning the object that was sent the message = TornOff. So, ╥this╙
** = CPaneMDEF::itsTearOffMenu which ITearChore stores in the latter's
** "itsTearOffMenu". The new CTearChore is then passed to:
** gApplication->AssignUrgentChore(newTearChore);
**
** Your app will then call newTearChore->Perform which calls:
** CTearChore::itsTearOffMenu->MoveToCorner();
** MoveToCorner eventually calls _MoveWindow passing true as the update parm.
** An update Event occurs and myMenu->Draw gets called because myMenu is
** a sub-view of the torn-off window. */
} /* ITearMenuDir */
void CTearMenuDir::DoCommand (long theCommand) {
if (HiShort(-theCommand) == ((CGridSelector*)itsPane)->GetCommandBase())
gGopher->DoCommand(theCommand);
else inherited::DoCommand(theCommand);
} /* DoCommand */
/* end: "CmyTear.c" */